home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / plotting / gnuplot3.lzh / gnuplot / plot.h < prev    next >
C/C++ Source or Header  |  1991-09-05  |  12KB  |  477 lines

  1. /* GNUPLOT - plot.h */
  2. /*
  3.  * Copyright (C) 1986, 1987, 1990, 1991   Thomas Williams, Colin Kelley
  4.  *
  5.  * Permission to use, copy, and distribute this software and its
  6.  * documentation for any purpose with or without fee is hereby granted, 
  7.  * provided that the above copyright notice appear in all copies and 
  8.  * that both that copyright notice and this permission notice appear 
  9.  * in supporting documentation.
  10.  *
  11.  * Permission to modify the software is granted, but not the right to
  12.  * distribute the modified code.  Modifications are to be distributed 
  13.  * as patches to released version.
  14.  *  
  15.  * This software is provided "as is" without express or implied warranty.
  16.  * 
  17.  *
  18.  * AUTHORS
  19.  * 
  20.  *   Original Software:
  21.  *     Thomas Williams,  Colin Kelley.
  22.  * 
  23.  *   Gnuplot 2.0 additions:
  24.  *       Russell Lang, Dave Kotz, John Campbell.
  25.  *
  26.  *   Gnuplot 3.0 additions:
  27.  *       Gershon Elber and many others.
  28.  * 
  29.  * Send your comments or suggestions to 
  30.  *  pixar!info-gnuplot@sun.com.
  31.  * This is a mailing list; to join it send a note to 
  32.  *  pixar!info-gnuplot-request@sun.com.  
  33.  * Send bug reports to
  34.  *  pixar!bug-gnuplot@sun.com.
  35.  */
  36.  
  37. #define PROGRAM "G N U P L O T"
  38. #define PROMPT "gnuplot> "
  39. #if defined(AMIGA_LC_5_1) || defined(AMIGA_AC_5)
  40. #define SHELL "NewShell"
  41. #else /* AMIGA */
  42. #define SHELL "/bin/sh"        /* used if SHELL env variable not set */
  43. #endif /* AMIGA  */
  44.  
  45. #define SAMPLES 100        /* default number of samples for a plot */
  46. #define ISO_SAMPLES 10        /* default number of isolines per splot */
  47. #define ZERO    1e-8        /* default for 'zero' set option */
  48.  
  49. #ifndef TERM
  50. /* default terminal is "unknown"; but see init_terminal */
  51. #define TERM "unknown"
  52. #endif
  53.  
  54. #define TRUE 1
  55. #define FALSE 0
  56.  
  57.  
  58. #define Pi 3.141592653589793
  59. #define DEG2RAD (Pi / 180.0)
  60.  
  61.  
  62. #define MIN_CRV_POINTS 100        /* minimum size of points[] in curve_points */
  63. #define MIN_SRF_POINTS 1000        /* minimum size of points[] in surface_points */
  64.  
  65. #define MAX_LINE_LEN 1024    /* maximum number of chars allowed on line */
  66. #define MAX_TOKENS 200
  67. #define MAX_ID_LEN 50        /* max length of an identifier */
  68.  
  69.  
  70. #define MAX_AT_LEN 150        /* max number of entries in action table */
  71. #define STACK_DEPTH 100
  72. #define NO_CARET (-1)
  73.  
  74.  
  75. #define MAX_NUM_VAR    2    /* Ploting projection of func. of max. two vars. */
  76.  
  77. #define MAP3D_CARTESIAN        0    /* 3D Data mapping. */
  78. #define MAP3D_SPHERICAL        1
  79. #define MAP3D_CYLINDRICAL    2
  80.  
  81. #define CONTOUR_NONE    0    /* Where to place contour maps if at all. */
  82. #define CONTOUR_BASE    1
  83. #define CONTOUR_SRF    2
  84. #define CONTOUR_BOTH    3
  85.  
  86. #define CONTOUR_KIND_LINEAR    0 /* See contour.h in contours subdirectory. */
  87. #define CONTOUR_KIND_CUBIC_SPL    1
  88. #define CONTOUR_KIND_BSPLINE    2
  89.  
  90. #define ANGLES_RADIANS    0
  91. #define ANGLES_DEGREES    1
  92.  
  93.  
  94. #if defined(AMIGA_LC_5_1) || defined(AMIGA_AC_5)
  95. #define OS "Amiga "
  96. #endif
  97.  
  98.  
  99. #ifdef vms
  100. #define OS "VMS "
  101. #endif
  102.  
  103.  
  104. #ifdef unix
  105. #define OS "unix "
  106. #endif
  107.  
  108.  
  109. #ifdef MSDOS
  110. #define OS "MS-DOS "
  111. #endif
  112.  
  113.  
  114. #ifndef OS
  115. #define OS ""
  116. #endif
  117.  
  118.  
  119. /*
  120.  * Note about VERYLARGE:  This is the upper bound double (or float, if PC)
  121.  * numbers. This flag indicates very large numbers. It doesn't have to 
  122.  * be the absolutely biggest number on the machine.  
  123.  * If your machine doesn't have HUGE, or float.h,
  124.  * define VERYLARGE here. 
  125.  *
  126.  * example:
  127. #define VERYLARGE 1e38
  128.  */
  129.  
  130. #ifdef PC
  131. #include <float.h>
  132. #define VERYLARGE FLT_MAX
  133. #else
  134. #if defined( vms ) || defined( _CRAY ) || defined( NEXT )
  135. #include <float.h>
  136. #define VERYLARGE DBL_MAX
  137. #else
  138. #if defined(AMIGA_AC_5) || defined(AMIGA_LC_5_1)
  139. #include <math.h>
  140. #define VERYLARGE HUGE
  141. #else
  142. #define VERYLARGE HUGE
  143. #endif
  144. #endif
  145. #endif
  146.  
  147.  
  148. #define END_OF_COMMAND (c_token >= num_tokens || equals(c_token,";"))
  149.  
  150. #ifdef vms
  151.  
  152.  
  153. #define is_comment(c) ((c) == '#' || (c) == '!')
  154. #define is_system(c) ((c) == '$')
  155.  
  156.  
  157. #else /* vms */
  158.  
  159.  
  160. #define is_comment(c) ((c) == '#')
  161. #define is_system(c) ((c) == '!')
  162.  
  163.  
  164. #endif /* vms */
  165.  
  166. /* If you don't have vfork, then undefine this */
  167. #if defined(NOVFORK) || defined(MSDOS)
  168. # undef VFORK
  169. #else
  170. # ifdef unix
  171. #  define VFORK
  172. # endif
  173. #endif
  174.  
  175. /* 
  176.  * memcpy() comes by many names. The default is now to assume bcopy, 
  177.  * since it is the most common case. Define 
  178.  *  MEMCPY to use memcpy(), 
  179.  *  vms to use the vms function,
  180.  *  NOCOPY to use a handwritten version in parse.c
  181.  */
  182. #ifdef vms
  183. # define memcpy(dest,src,len) lib$movc3(&len,src,dest)
  184. #else
  185. # if defined(MEMCPY) || defined(MSDOS)
  186.    /* use memcpy directly */
  187. # else 
  188. #  ifdef NOCOPY
  189.     /* use the handwritten memcpy in parse.c */
  190. #  else
  191.     /* assume bcopy is in use */
  192. #   define memcpy(dest,src,len) bcopy(src,dest,len)
  193. #  endif /* NOCOPY */
  194. # endif /* MEMCPY || MSDOS */
  195. #endif /* vms */
  196.  
  197. /*
  198.  * In case you have MEMSET instead of BZERO. If you have something 
  199.  * else, define bzero to that something.
  200.  */
  201. #if defined(MEMSET) || defined(MSDOS)
  202. #define bzero(dest,len)  (void)(memset(dest, (char)NULL, len))
  203. #endif /* MEMSET || MSDOS */
  204.  
  205. /* Give the name of your gamma function, or undefine it if you have none.  */
  206. #if defined(NOGAMMA) || defined(MSDOS)
  207. # undef GAMMA
  208. #else
  209. # ifndef GAMMA
  210. #  define GAMMA gamma
  211. # endif /* GAMMA */
  212. #endif /* NOGAMMA ||MSDOS */
  213.  
  214. #define top_of_stack stack[s_p]
  215.  
  216. typedef int BOOLEAN;
  217.  
  218. #ifdef __ZTC__
  219. typedef int (*FUNC_PTR)(...);
  220. #else
  221. typedef int (*FUNC_PTR)();
  222. #endif
  223.  
  224. #if defined(AMIGA_LC_5_1) || defined(AMIGA_AC_5)
  225. enum operators {
  226.     PUSH, PUSHC, PUSHD1, PUSHD2, CALL, CALL2, LNOT, BNOT, UMINUS, LOR, LAND,
  227.     BOR, XOR, BAND, EQ, NE, GT, LT, GE, LE, PLUS, MINUS, MULT, DIV,
  228.     MOD, POWER, FACTORIAL, ABOOL, JUMP, JUMPZ, JUMPNZ, JTERN, SF_START
  229. };
  230. #else
  231. enum operators {
  232.     PUSH, PUSHC, PUSHD1, PUSHD2, CALL, CALL2, LNOT, BNOT, UMINUS, LOR, LAND,
  233.     BOR, XOR, BAND, EQ, NE, GT, LT, GE, LE, PLUS, MINUS, MULT, DIV,
  234.     MOD, POWER, FACTORIAL, BOOL, JUMP, JUMPZ, JUMPNZ, JTERN, SF_START
  235. };
  236. #endif
  237.  
  238.  
  239. #define is_jump(operator) ((operator) >=(int)JUMP && (operator) <(int)SF_START)
  240.  
  241.  
  242. enum DATA_TYPES {
  243.     INT, CMPLX
  244. };
  245.  
  246.  
  247. enum PLOT_TYPE {
  248.     FUNC, DATA, FUNC3D, DATA3D
  249. };
  250.  
  251.  
  252. enum PLOT_STYLE {
  253.     LINES, POINTS, IMPULSES, LINESPOINTS, DOTS, ERRORBARS
  254. };
  255.  
  256. enum JUSTIFY {
  257.     LEFT, CENTRE, RIGHT
  258. };
  259.  
  260. struct cmplx {
  261.     double real, imag;
  262. };
  263.  
  264.  
  265. struct value {
  266.     enum DATA_TYPES type;
  267.     union {
  268.         int int_val;
  269.         struct cmplx cmplx_val;
  270.     } v;
  271. };
  272.  
  273.  
  274. struct lexical_unit {    /* produced by scanner */
  275.     BOOLEAN is_token;    /* true if token, false if a value */ 
  276.     struct value l_val;
  277.     int start_index;    /* index of first char in token */
  278.     int length;            /* length of token in chars */
  279. };
  280.  
  281.  
  282. struct ft_entry {        /* standard/internal function table entry */
  283.     char *f_name;        /* pointer to name of this function */
  284.     FUNC_PTR func;        /* address of function to call */
  285. };
  286.  
  287.  
  288. struct udft_entry {                /* user-defined function table entry */
  289.     struct udft_entry *next_udf;         /* pointer to next udf in linked list */
  290.     char udf_name[MAX_ID_LEN+1];         /* name of this function entry */
  291.     struct at_type *at;            /* pointer to action table to execute */
  292.     char *definition;             /* definition of function as typed */
  293.     struct value dummy_values[MAX_NUM_VAR];    /* current value of dummy variables */
  294. };
  295.  
  296.  
  297. struct udvt_entry {            /* user-defined value table entry */
  298.     struct udvt_entry *next_udv; /* pointer to next value in linked list */
  299.     char udv_name[MAX_ID_LEN+1]; /* name of this value entry */
  300.     BOOLEAN udv_undef;        /* true if not defined yet */
  301.     struct value udv_value;    /* value it has */
  302. };
  303.  
  304.  
  305. union argument {            /* p-code argument */
  306.     int j_arg;                /* offset for jump */
  307.     struct value v_arg;        /* constant value */
  308.     struct udvt_entry *udv_arg;    /* pointer to dummy variable */
  309.     struct udft_entry *udf_arg; /* pointer to udf to execute */
  310. };
  311.  
  312.  
  313. struct at_entry {            /* action table entry */
  314.     enum operators index;    /* index of p-code function */
  315.     union argument arg;
  316. };
  317.  
  318.  
  319. struct at_type {
  320.     int a_count;                /* count of entries in .actions[] */
  321.     struct at_entry actions[MAX_AT_LEN];
  322.         /* will usually be less than MAX_AT_LEN is malloc()'d copy */
  323. };
  324.  
  325.  
  326. /* Defines the type of a coordinate */
  327. /* INRANGE and OUTRANGE points have an x,y point associated with them */
  328. enum coord_type {
  329.     INRANGE,                /* inside plot boundary */
  330.     OUTRANGE,                /* outside plot boundary, but defined */
  331.     UNDEFINED                /* not defined at all */
  332. };
  333.   
  334. #ifdef PC
  335. typedef float coordval;        /* memory is tight on PCs! */
  336. #else
  337. typedef double coordval;
  338. #endif
  339.  
  340. struct coordinate {
  341.     enum coord_type type;    /* see above */
  342.     coordval x, y, z;
  343.     coordval ylow, yhigh;    /* ignored in 3d */
  344. };
  345.  
  346. struct curve_points {
  347.     struct curve_points *next_cp;    /* pointer to next plot in linked list */
  348.     enum PLOT_TYPE plot_type;
  349.     enum PLOT_STYLE plot_style;
  350.     char *title;
  351.     int line_type;
  352.     int point_type;
  353.      int p_max;                    /* how many points are allocated */
  354.     int p_count;                    /* count of points in points */
  355.     struct coordinate *points;
  356. };
  357.  
  358. struct gnuplot_contours {
  359.     struct gnuplot_contours *next;
  360.     struct coordinate *coords;
  361.     int num_pts;
  362. };
  363.  
  364. struct iso_curve {
  365.     struct iso_curve *next;
  366.      int p_max;                    /* how many points are allocated */
  367.     int p_count;                    /* count of points in points */
  368.     struct coordinate *points;
  369. };
  370.  
  371. struct surface_points {
  372.     struct surface_points *next_sp;    /* pointer to next plot in linked list */
  373.     enum PLOT_TYPE plot_type;
  374.     enum PLOT_STYLE plot_style;
  375.     char *title;
  376.     int line_type;
  377.     int point_type;
  378.     int has_grid_topology;
  379.     int num_iso_read;  /* Data files only - num of isolines read from file. */
  380.     struct gnuplot_contours *contours;    /* Not NULL If have contours. */
  381.     struct iso_curve *iso_crvs;
  382. };
  383.  
  384. struct termentry {
  385.     char *name;
  386.     char *description;
  387.     unsigned int xmax,ymax,v_char,h_char,v_tic,h_tic;
  388.     FUNC_PTR options,init,reset,text,scale,graphics,move,vector,linetype,
  389.         put_text,text_angle,justify_text,point,arrow;
  390. };
  391.  
  392.  
  393. struct text_label {
  394.     struct text_label *next;    /* pointer to next label in linked list */
  395.     int tag;            /* identifies the label */
  396.     double x,y,z;
  397.     enum JUSTIFY pos;
  398.     char text[MAX_LINE_LEN+1];
  399. };
  400.  
  401. struct arrow_def {
  402.     struct arrow_def *next;    /* pointer to next arrow in linked list */
  403.     int tag;            /* identifies the arrow */
  404.     double sx,sy,sz;        /* start position */
  405.     double ex,ey,ez;        /* end position */
  406.     BOOLEAN head;            /* arrow has a head or not */
  407. };
  408.  
  409. /* Tic-mark labelling definition; see set xtics */
  410. struct ticdef {
  411.     int type;                /* one of three values below */
  412. #define TIC_COMPUTED 1        /* default; gnuplot figures them */
  413. #define TIC_SERIES 2        /* user-defined series */
  414. #define TIC_USER 3            /* user-defined points */
  415.     union {
  416.        struct {            /* for TIC_SERIES */
  417.           double start, incr;
  418.           double end;        /* ymax, if VERYLARGE */
  419.        } series;
  420.        struct ticmark *user;    /* for TIC_USER */
  421.     } def;
  422. };
  423.  
  424. /* Defines one ticmark for TIC_USER style.
  425.  * If label==NULL, the value is printed with the usual format string.
  426.  * else, it is used as the format string (note that it may be a constant
  427.  * string, like "high" or "low").
  428.  */
  429. struct ticmark {
  430.     double position;        /* where on axis is this */
  431.     char *label;            /* optional (format) string label */
  432.     struct ticmark *next;    /* linked list */
  433. };
  434.  
  435. /*
  436.  * SS$_NORMAL is "normal completion", STS$M_INHIB_MSG supresses
  437.  
  438.  * printing a status message.
  439.  * SS$_ABORT is the general abort status code.
  440.  from:    Martin Minow
  441.     decvax!minow
  442.  */
  443. #ifdef    vms
  444. #include        <ssdef.h>
  445. #include        <stsdef.h>
  446. #define    IO_SUCCESS    (SS$_NORMAL | STS$M_INHIB_MSG)
  447. #define    IO_ERROR    SS$_ABORT
  448. #endif /* vms */
  449.  
  450.  
  451. #ifndef    IO_SUCCESS    /* DECUS or VMS C will have defined these already */
  452. #define    IO_SUCCESS    0
  453. #endif
  454. #ifndef    IO_ERROR
  455. #define    IO_ERROR    1
  456. #endif
  457.  
  458. /* Some key global variables */
  459. extern BOOLEAN screen_ok;
  460. extern BOOLEAN term_init;
  461. extern BOOLEAN undefined;
  462. extern struct termentry term_tbl[];
  463.  
  464. extern char *alloc();
  465. /* allocating and managing curve_points structures */
  466. extern struct curve_points *cp_alloc();
  467. extern int cp_extend();
  468. extern int cp_free();
  469. /* allocating and managing surface_points structures */
  470. extern struct surface_points *sp_alloc();
  471. extern int sp_replace();
  472. extern int sp_free();
  473. /* allocating and managing is_curve structures */
  474. extern struct iso_curve *iso_alloc();
  475. extern int iso_extend();
  476. extern int iso_free();
  477.